import {Component} from 'react';
import PropTypes from "prop-types";
import Item from "../Item/index.jsx";
import "./index.scss"

export default class List extends Component {
  static propTypes = {
    todos: PropTypes.array.isRequired,
    chooseTodo: PropTypes.func.isRequired,
    delTodo: PropTypes.func.isRequired,
  }

  render() {
    const {todos, chooseTodo, delTodo} = this.props
    const total = todos.length
    return (
      <div className="todo-list">
        {total ?
          todos.map(item => {
            return <Item {...item} key={item.id} chooseTodo={chooseTodo} delTodo={delTodo}/>
          }) :
          <div className="todo-empty">暂无数据</div>
        }
      </div>
    );
  }
}

